<template>
    <el-form ref="form" :rules="ruleCustom" :model="app" v-loading="spin">
        <el-form-item prop="platform" label="平台">
            <el-radio-group v-model="app.platform">
                <el-radio label="1">
                    <i class="el-icon-android"/>
                    <span>安卓</span>
                </el-radio>
                <el-radio label="2">
                    <i class="el-icon-apple"/>
                    <span>IOS</span>
                </el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item prop="must" label="强制更新">
            <el-radio-group v-model="app.must">
                <el-radio label="0">
                    <span>否</span>
                </el-radio>
                <el-radio label="1">
                    <span>是</span>
                </el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item prop="version" label="版本号">
            <el-input v-model="app.version" :maxlength="250" placeholder="最多250个字符"></el-input>
        </el-form-item>
        <el-form-item prop="url" label="下载地址">
            <el-input v-model="app.url" :maxlength="250" placeholder="最多250个字符"></el-input>
        </el-form-item>
        <el-form-item prop="log" label="说明">
            <el-input type="textarea" :rows="5" v-model="app.log" :maxlength="250" placeholder="最多250个字符"></el-input>
        </el-form-item>
        <el-form-item class="t-center">
            <el-button type="primary" @click="submit">提交</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    import {appVersion} from "@/api";

    export default {
        data() {
            return {
                column: [
                    {title: '名称', key: 'name'},
                    {title: '操作', slot: 'act'},
                ],
                app: {
                    platform: '1',
                    must: '0',
                    version: '',
                    log: '',
                    url: ''
                },
                spin: false,
                //验证信息
                ruleCustom: {
                    platform: [
                        {required: true, message: '请选择平台', trigger: 'change'},
                    ]
                    , must: [
                        {required: true, message: '请设置是否强制更新', trigger: 'change'},
                    ]
                    , version: [
                        {required: true, message: '请填写版本号', trigger: 'blur'},
                    ]
                    , log: [
                        {required: true, message: '请填写版本说明', trigger: 'blur'},
                    ]
                    , url: [
                        {required: true, type: 'url', message: '请填写正确的下载链接', trigger: 'blur'},
                    ]
                }
            }
        }
        , methods: {
            //确认修改
            submit() {
                this.$submit(this.$refs['form'], () => {
                    this.spin = true;
                    appVersion('post', this.app, () => {
                        this.spin = false;
                        this.$emit('close', true);
                    }, () => {
                        this.spin = false;
                    })
                });
            }
        }
    }
</script>

<style scoped>

</style>
